package com.ganbo.stock.repository;

import com.ganbo.stock.entity.FundStockLast;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


@Repository
public interface FundStockLastRepository extends JpaRepository<FundStockLast, Long> {

    void deleteFundStockLastByStatistics(Date statistics);

    List<FundStockLast> findFundStockLastByStatistics(Date statistics);

    //查询当天跌幅大于某个点的股票(低吸)
    List<FundStockLast> findFundStockLastByPcLessThanEqualAndStatistics(BigDecimal pc, Date statistics);

    //查询当天涨幅大于某个点的股票(高抛)
    List<FundStockLast> findFundStockLastByPcGreaterThanEqualAndStatistics(BigDecimal pc, Date statistics);


    //    @Modifying(clearAutomatically = true)
    @Modifying
    @Query("UPDATE FundStockLast o set o.fm = :fm, o.h = :h, o.hs = :hs," +
            "o.lb = :lb, o.l = :l, o.lt = :lt," +
            "o.pe = :pe, o.pc = :pc, o.p = :p," +
            "o.sz = :sz, o.cje = :cje, o.ud = :ud," +
            "o.v = :v, o.vb = :vb, o.yc = :yc," +
            "o.zf = :zf, o.t = :t WHERE o.id = :id")
    int updateFundStockLastToDayReal(BigDecimal fm, BigDecimal h, BigDecimal hs,
                                     BigDecimal lb, BigDecimal l, BigDecimal lt,
                                     BigDecimal pe, BigDecimal pc, BigDecimal p,
                                     BigDecimal sz, BigDecimal cje, BigDecimal ud,
                                     BigDecimal v, BigDecimal vb, BigDecimal yc,
                                     BigDecimal zf, String t, Long id);

}
